<%-- 
    Document   : XemVBNoiBo
    Created on : Jun 19, 2011, 9:05:05 PM
    Author     : pdaitoan
--%>

<%@page import="java.util.List"%>
<%@page import="javax.jdo.Query"%>
<%@page import="Entity.Document"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="Servlet.PMF"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Entity.BDoc"%>
<%@page import="DataAccess.BDocAccess"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="../js/jquery-1.5.1.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.core.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
        <link  type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css"/>
        <style type="text/css">
            @import "../css/main.css";
            @import "../css/menu.css";
            @import "../menu/menu_style.css";
            @import "../css/VanBanNoiBo.css";
            @import "../css/jquery.ui.datepicker.css";
            @import "../css/jquery.ui.theme.css";
            .ui-widget{font-size:0.7em;}
            .ui-helper-hidden-accessible{clip:auto;}
        </style>
        <script>
                $(function() {
                        $( ".datepicker" ).datepicker();
                });
	</script>
        <title> ViewBDoc</title>
    </head>
    <body>
        <%@include file="../header.jsp" %>
         <%
            Long ID = Long.parseLong(request.getParameter("BID"));
            BDocAccess idoc = new BDocAccess();
            BDoc entity = new BDoc();
            entity = idoc.getBDocByID(ID);
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        %>
        <div id="vbnb">
        	Xem chi tiết văn bản nội bộ
        </div>
        <div >
        <form name="form1" action="/bdoc" method="post" id="form1">
            <input type="hidden" name="action" value="publish"/>
            <input type="hidden" name="txtBDocID" value="<% out.print(entity.getBDocID()); %>"/>
                <table width="957" height="466" border="0" align="center" cellpadding="1" cellspacing="1" id="table">
                <tbody>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="2" id="td5">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td colspan="2" id="td5">&nbsp;</td>
                </tr>
                <tr>
                  <td width="122" height="32">Số ghi sổ</td>
                  <td colspan="2" id="td"><% out.print(entity.getDocNum()); %></td>
                  <td width="7">&nbsp;</td>
                  <td width="152">Trả lời VB nội bộ số</td>
                  <td colspan="2" id="td">
                      <p><% out.print(entity.getReplyReceiveName()); %></p></td>
            </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="2" id="td2">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td colspan="2" id="td2">&nbsp;</td>
                </tr>
                <tr>
                  <td height="32">Người ký</td>
                  <td colspan="3" id="td">
                      <%
                        // Get FullNameByID
                        user = new UserAccess();
                        Long SignedID = Long.parseLong(entity.getSignByName().trim());
                        Account acc = new Account();
                        acc = user.getUserByID(SignedID);
                        if (acc != null)
                            out.print(acc.getFullname());
                      %>
                  </td>
                  <td>&nbsp;</td>
                  <td>Ngày ký</td>
                  <td colspan="2" id="td"><p><% out.print(df.format(entity.getSignDate())); %></p></td>
                  </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="6" id="td3">&nbsp;</td>
                </tr>
                <tr>
                  <td height="63">Trích yếu</td>
                  <td colspan="6" id="td"><% out.print(entity.getSubject()); %></td>
                </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="6" id="td4">&nbsp;</td>
                </tr>
                <tr>
                  <td height="94">Ghi chú</td>
                  <td colspan="6" id="td"><% out.print(entity.getNotes()); %></td>
                </tr>
                <tr>
                  <td height="22">Toàn văn</td>
                  <td colspan="4">
                      <%
                        if (entity.getDocumentName() != null)
                        {
                            PersistenceManager pmf = PMF.get().getPersistenceManager();
                            //String query = "select from " + Document.class.getName();
                            Query q = pmf.newQuery(Document.class,"name == fname");
                            q.declareParameters("String fname");
                            List<Document> list = (List<Document>)q.execute(entity.getDocumentName().trim());
                            Document doc = new Document();
                            if (list.size() > 0)
                            {
                                doc = list.get(0);
                                out.println("<a href=\"/serve?blob-key=" + doc.getKey() + "\" target=\"_blank\">"+ doc.getName() +"</a>");
                            }
                            pmf.close();
                        }
                      %>
                  </td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td height="45">Ngày soạn thảo</td>
                  <td colspan="2" id="td"><% out.print(df.format(entity.getDraftDate())); %></td>
                  <td>&nbsp;</td>
                  <td>Tên người soạn thảo</td>
                  <td colspan="2" id="td"><% out.print(entity.getDraftUserName()); %></td>
                </tr>
                
                <tr>
                  <td>&nbsp;</td>
                  <td colspan="2">
                  <%
                     String role = account.getRole();
                     if (role.trim().equals("director"))
                     {
                  %>
                        <input type="submit" name="btnPublish" id="button" value="Phát hành">
                  <%
                     }
                  %>
                      &nbsp;&nbsp;&nbsp;&nbsp;
                  <INPUT TYPE="BUTTON" VALUE="Trở về" id="button" ONCLICK="history.go(-1)"></td>
                  <td width="174"> &nbsp; &nbsp; &nbsp;
                  <label></label></td>
                  <td width="112">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                </tbody>
              </table>
   	</form>
        </div>
    </body>
</html>
